package com.pan.admin.common.constant;

import com.gitee.apanlh.util.algorithm.digest.DigestType;
import com.gitee.apanlh.util.algorithm.digest.SHA;
import org.springframework.web.multipart.MultipartFile;

/**
 * 上传地址
 */
public class UploadConstant {

    /**
     * 获取转化后的地址
     *
     * @param path
     * @param file
     * @return
     */
    public static String getPath(String path, MultipartFile file) {
        if (file == null) {
            return null;
        }

        String originalFilename = file.getOriginalFilename();
        String prefix = originalFilename.substring(originalFilename.lastIndexOf("."));

        StringBuilder builder = new StringBuilder(path).append(SHA.create(DigestType.SHA_1).digestToHex(prefix)).append(prefix);
        return builder.toString();
    }
}
